//#include <sys.h>

#include <GPIO_config.h>
//
//PP for Push-Pull  &  OD for Open-Drain
//GP for General-Purpose  &  AF for Alternative-Function
//
//enum Pin_Mode{GP_PP, GP_OD, AF_PP, AF_OD, Anlog, NC_In, PD_In, PU_In};

unsigned char GPIO_config(GPIO_TypeDef *GPIO, unsigned char bit_num, unsigned int mode)
{
	if(bit_num > 15)
		return 0;
	if(mode == PU_In)
	{
		mode = PD_In;
		GPIO->ODR |= (1 << bit_num);
	}
	else if(mode == PD_In)
	{
		GPIO->ODR &= ~(1 << bit_num);
	}

	if(bit_num > 7)
	{
		bit_num -= 8;
		bit_num <<= 2;
		GPIO->CRH &= ~(0x0000000F << bit_num);
		GPIO->CRH |= mode << bit_num;
	}
	else
	{
		bit_num <<= 2;
		GPIO->CRL &= ~(0x0000000F << bit_num);
		GPIO->CRL |= mode << bit_num;
	}
	return 1;
}

